package com.xlisteven.springboot_ssm_tkmapper.service.impl;

import com.xlisteven.springboot_ssm_tkmapper.bean.User;
import com.xlisteven.springboot_ssm_tkmapper.mapper.UserMapper;
import com.xlisteven.springboot_ssm_tkmapper.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

   @Autowired
   UserMapper userMapper;
    @Override
    public List<User> findAllUser() {
        return userMapper.selectAll();
    }

    @Override
    public User findUserById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateByPrimaryKey(user);
    }

    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int saveUser(User user) {
        int result = userMapper.insert(user);
        return result;
    }

    @Override
    public List<User> search(String name) {
        return userMapper.search("%"+name+"%");
    }
}
